import fetch from 'dva/fetch';
import React from 'react';
import { message } from 'antd';

const uploadPic = async (files, objectId, objectName, objectField) => {
    let formData = new FormData();
    files.forEach(element => {
        formData.append("files", element.originFileObj);
    });
    formData.append("objectId", objectId);
    formData.append("objectName", objectName);
    formData.append("objectField", objectField);

    var resp = {};
    await fetch("http://localhost:21021/Home/UploadFilesAsync", {
        method: 'POST',
        headers: {
            'Authorization': 'Bearer ' + localStorage.getItem("access-token"),
        },
        body: formData,
    }).then((response) => response.json())
        .then((responseData) => {
            resp = responseData;
        }).catch((err) => {
            message.error("图片上传失败");
        });
    if (resp && resp.success) {
        return resp.result;
    }
    else {
        return "";
    }
}
export default uploadPic